package com.yimin.floatball

import android.accessibilityservice.AccessibilityService
import android.app.Service
import android.content.Intent
import android.os.IBinder
import android.util.Log
import android.view.accessibility.AccessibilityEvent


class FloatBallService : AccessibilityService() {

    companion object {
        const val TYPE_ADD = 0
        const val TYPE_DEL = 1
    }

    override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
        val data = intent?.extras
        data?.let {
            when(it.getInt("type")) {
                TYPE_ADD -> {
                    FloatWindowManager.addBallView(this)
                }
                TYPE_DEL -> {
                    FloatWindowManager.removeBallView(this)
                }
            }
        }
        return super.onStartCommand(intent, flags, startId)
    }

    override fun onAccessibilityEvent(event: AccessibilityEvent?) {
        Log.d(TAG, "onAccessibilityEvent: ${event?.action}")
    }

    override fun onInterrupt() {
    }

    override fun onDestroy() {
        super.onDestroy()
        FloatWindowManager.removeBallView(this)
        Log.d(TAG, "FloatBallService onDestroy: ")

    }

}